#include <iostream>
#include <pthread.h>

class Mutex
{
public:
    // 去掉不要的赋值与拷贝
    Mutex(const Mutex &) = delete;
    const Mutex &operator=(const Mutex &) = delete;

    Mutex()
    {
        pthread_mutex_init(&tid, NULL);
    }
    ~Mutex()
    {
        pthread_mutex_destroy(&tid);
    }
    void lock()
    {
        pthread_mutex_lock(&tid);
    }
    void unlock()
    {
        pthread_mutex_unlock(&tid);
    }
    pthread_mutex_t *GetmMutexOriginal()
    {
        return &tid;
    }

private:
    pthread_mutex_t tid;
};

class LockGuard
{
public:
    LockGuard(Mutex &mutex) : _mutex(mutex)
    {
        _mutex.lock();
    }
    ~LockGuard()
    {
        _mutex.unlock();
    }

private:
    Mutex &_mutex;
};
